// pages/user/member.js
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    imageUrlFix: app.d.imageUrlFix,
    member: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      var that = this;
      that.d_user_list();
  },

  // 获取分销商的下线会员信息
  d_user_list:function(){
     var that = this;
     app.request("WxOrderListService", "queryDistributorMember", { userId: app.d.userId }, function (data) {
       var list = data.memberList;
       var elist = [];
       for (let i = 0; i < list.length; i++) {
         if (list[i] == null) {
           continue;
         }
         if (list[i].user_picture == '' || list[i].user_picture == undefined || list[i].user_picture == 'null') {
           list[i]['user_picture'] = "/images/hui.png";
           // list[i]['choose'] = 0;
         } else if (list[i].user_picture.indexOf('https') < 0) {
           list[i]['choose'] = 1;
         }
         elist.push(list[i]);
       }
       that.setData({
         member: elist,
       });
     });
 },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
      var data = new Date();
      var shared = data.getTime()+"";
      var shareId = shared.substring(8, shared.length) + app.d.userId;
      return {
          title: '小城鱼铺',
          path: '/pages/index/index?duid=' + app.d.userId + "&shareId=" + shareId,
          success: function(res) {
              app.request("DistributorService", "shareLog", {
                  uid: app.d.userId,
                  shareId: shareId,
              }, function(data){
                  // 分享成功
                  console.log(res);
              })
          },
          fail: function(res) {
              // 分享失败
              console.log(res);
          }
      }
  }
})